from django.shortcuts import render
from rest_framework import viewsets
from drf_spectacular.utils import extend_schema_view, extend_schema, OpenApiParameter
from .models import Room
from .serializers import RoomSerializer
from .pagination import CustomPagination

# Create your views here.
@extend_schema_view(
    list=extend_schema(
        summary='获取机房列表',  # 自定义接口摘要
        description='该接口返回所有机房的列表。',  # 自定义接口描述
        parameters=[
            OpenApiParameter(name='limit', type=int, description='每页显示的机房数量', required=False),
            OpenApiParameter(name='page', type=int, description='页码', required=False),
        ],
    ),
    retrieve=extend_schema(
        summary='获取机房详情',
        description='该接口根据机房 ID 返回机房的详细信息。',
    ),
    create=extend_schema(
        summary='创建新机房',
        description='该接口用于创建新的机房。',
        request=RoomSerializer
    ),
    update=extend_schema(
        summary='更新机房信息',
        description='该接口用于更新指定机房的信息。',
        request=RoomSerializer,
    ),
    partial_update=extend_schema(
        summary='部分更新机房信息',
        description='该接口用于部分更新指定机房的信息。',
        request=RoomSerializer,
    ),
    destroy=extend_schema(
        summary='删除机房',
        description='该接口用于删除指定的机房。',
    ),
)
@extend_schema(tags = ["机房管理接口"])
class RoomViewSet(viewsets.ModelViewSet):
    """机房管理接口"""
    queryset = Room.objects.all()
    serializer_class = RoomSerializer
    pagination_class = CustomPagination  # 使用自定义分页器